public class test {
    //输入一个链表，输出该链表中倒数第k个结点:双指针，先让fast走k-1步，注意会不会直接走到null，然后让fast和slow一起走，直到fast到最后
    public ListNode FindKthToTail(ListNode head,int k) {
        if(head == null) {
            return null;
        }
        ListNode fast = head;
        ListNode slow = head;
        int count = 0;
        if(k <= 0)
            return null;
        while(count++ < k-1) {
            if(fast.next!= null)//这里不能写成fast!=null(这样fast已经走到了null)
                fast = fast.next;
            else
                return null;
        }
        while(fast != null && fast.next != null) {
            fast = fast.next;
            slow = slow.next;
        }
        return slow;
    }
}
